package com.hunan.api.catv.action.news.ugc;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.common.Constants;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.entity.vo.UgcNewsVo;
import com.hunan.api.catv.service.biz.ugc.UgcNewsBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author jiang zhuan
 * @version 1.0
 * @description ugc
 * @date 2020/9/23 0023
 * @package com.hunan.api.catv.action.news.ugc
 * @company 湖南有线
 */
@RestController
@RequestMapping(Api.ugc)
@Validated
public class UgcNewsAction extends BaseAction {

    @Autowired
    UgcNewsBiz ugcNewsBiz;

    @GetMapping(value = {"/list/{activityId}/{pageNum}/{pageSize}/{tag}", "/list/{activityId}/{pageNum}/{pageSize}"})
    public Result passList(@PathVariable @NotNull(message = "activityId required") Integer activityId, @PathVariable Integer pageNum, @PathVariable Integer pageSize, @PathVariable(required = false) String tag, HttpServletRequest request) {
        return buildOK(ugcNewsBiz.ugcNewsList(activityId, pageNum, pageSize, Constants.UGC_PASS_VIDEO, tag, getMemberIdV2(request)), "");
    }

    @MemberAuth
    @PostMapping("/update/praise/{ugcId}/{type}")
    public Result updatePraiseCount(@PathVariable @NotNull(message = "ugcId required") String ugcId, @PathVariable @Pattern(regexp = "[01]", message = "type [0 or 1] required") String type, HttpServletRequest request) {
        return buildOK(ugcNewsBiz.updatePraiseCount(ugcId, getMemberIdV2(request), type), "");
    }

    @GetMapping("/tags/{tagKey}")
    public Result getTags(@PathVariable @NotNull(message = "tagKey required") String tagKey) {
        return buildOK(ugcNewsBiz.getTags(tagKey), "");
    }

    /**
     * 保存用戶發佈視頻
     */
    @MemberAuth
    @PostMapping("/saveUserReleaseVideos")
    public Result saveUserReleaseVideos(@RequestBody UgcNewsVo ugcNewsVo, HttpServletRequest request) {
        return buildOK(ugcNewsBiz.saveUserReleaseVideos(ugcNewsVo, getMemberId(request)), "");
    }

    /**
     * 删除用户发布视频
     */
    @MemberAuth
    @DeleteMapping("/delUserReleaseVideos/{ugcId}")
    public Result delUserReleaseVideos(@PathVariable("ugcId") String ugcId, HttpServletRequest request) {
        return buildOK(ugcNewsBiz.delUserReleaseVideos(ugcId, getMemberId(request)), "");
    }

    /**
     * 获取个人发布视频列表
     */
    @MemberAuth
    @GetMapping("/getUserReleaseVideosByMemberId/{pageNum}/{pageSize}")
    public Result getUserReleaseVideosByMemberId(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize, HttpServletRequest request) {
        return buildOK(ugcNewsBiz.getUserReleaseVideosByMemberId(pageNum, pageSize, getMemberId(request)), "");
    }
}
